﻿using System.Collections;
using com.yoozoo.gta.Gameplay.RTS;
using UnityEngine;
using WorldMapBase.Tile.Pool;
namespace Yoozoo.Gameplay.RTS
{
    public class RTSClassPoolManager
    {
        private static MarchSquarePool _marchSquarePool;
        private static RoundFightFlyTextPool _roundFightFlyTextPool;
        static RoundAttackEffectPool _roundAttackEffectPool;
        private static SkillPool _skillPool;
        private static AttackHitPool _attackHitPool;
        private static SkillHitPool _skillHitPool;
        private static SkillNamePool _skillNamePool;
        private static PlayerBattleListPool _playerBattleListPool;
        private static LineInfoPool _lineInfoPool;
        private static MarchLinePointPool _marchLinePointPool;
        private static AttackHitTempPool _AttackHitTempPool;
        private static SkillHitElementListPool _SkillHitElementListPool;
        private static RtsServerInfoPool _rtsServerInfoPool;
        public void InitClassPool()
        {
            int squareNum = 500;

            _marchSquarePool = new MarchSquarePool(128);
            _marchSquarePool.OnInit(128);

            _roundFightFlyTextPool = new RoundFightFlyTextPool(64);
            _roundFightFlyTextPool.OnInit(64);

            _roundAttackEffectPool = new RoundAttackEffectPool(64);
            _roundAttackEffectPool.OnInit(64);

            _skillPool = new SkillPool(16);
            _skillPool.OnInit(16);

            _attackHitPool = new AttackHitPool(128);
            _attackHitPool.OnInit(128);

            _skillHitPool = new SkillHitPool(32);
            _skillHitPool.OnInit(32);

            _skillNamePool = new SkillNamePool(32);
            _skillNamePool.OnInit(32);

            _playerBattleListPool = new PlayerBattleListPool(64);
            _playerBattleListPool.OnInit(64);

            _lineInfoPool = new LineInfoPool(128);
            _lineInfoPool.OnInit(128);

            _marchLinePointPool = new MarchLinePointPool(64);
            _marchLinePointPool.OnInit(64);

            _AttackHitTempPool = new AttackHitTempPool(8);
            _AttackHitTempPool.OnInit(8);

            _SkillHitElementListPool = new SkillHitElementListPool(8);
            _SkillHitElementListPool.OnInit(8);
            
            _rtsServerInfoPool = new RtsServerInfoPool(128);
            _rtsServerInfoPool.OnInit(128);
        }

        public void Destroy()
        {
            _marchSquarePool.Destroy();
            _marchSquarePool = null;

            _roundFightFlyTextPool.Destroy();
            _roundFightFlyTextPool = null;

            _roundAttackEffectPool.Destroy();
            _roundAttackEffectPool = null;

            _skillPool.Destroy();
            _skillPool = null;

            _attackHitPool.Destroy();
            _attackHitPool = null;

            _skillHitPool.Destroy();
            _skillHitPool = null;

            _skillNamePool.Destroy();
            _skillNamePool = null;


            _playerBattleListPool.Destroy();
            _playerBattleListPool = null;

            _lineInfoPool.Destroy();
            _lineInfoPool = null;

            _marchLinePointPool.Destroy();
            _marchLinePointPool = null;

            _AttackHitTempPool.Destroy();
            _AttackHitTempPool = null;
            
            _SkillHitElementListPool.Destroy();
            _SkillHitElementListPool = null;
            
            _rtsServerInfoPool.Destroy();
            _rtsServerInfoPool = null;
        }
        
        public static RtsServerInfo GetRtsServerInfo()
        {
            return _rtsServerInfoPool.GetItem();
        }

        public static void RecoverRtsServerInfo(RtsServerInfo obj)
        {
            _rtsServerInfoPool.RecoverItem(obj);
        }
        
        public static SkillHitElementList GetSkillHitElementList()
        {
            return _SkillHitElementListPool.GetItem();
        }

        public static void RecoverSkillHitElementList(SkillHitElementList obj)
        {
            _SkillHitElementListPool.RecoverItem(obj);
        }
        public static AttackHitTemp GetAttackHitTemp()
        {
            return _AttackHitTempPool.GetItem();
        }

        public static void RecoverAttackHitTemp(AttackHitTemp obj)
        {
            _AttackHitTempPool.RecoverItem(obj);
        }
        public static MarchLinePoint GetMarchLinePoint()
        {
            return _marchLinePointPool.GetItem();
        }

        public static void RecoverMarchLinePoint(MarchLinePoint obj)
        {
            if (_marchSquarePool != null && obj != null)
            {
                _marchLinePointPool.RecoverItem(obj);
            }
        }

        public static LineInfo GetLineInfo()
        {
            if (_lineInfoPool == null)
            {
                return new LineInfo();
            }
            return _lineInfoPool.GetItem();
        }

        public static void RecoverLineInfo(LineInfo obj)
        {
            _lineInfoPool?.RecoverItem(obj);
        }


        public static PlayerBattleList GetPlayerBattleListPool()
        {
            return _playerBattleListPool.GetItem();
        }
        public static void RecoverPlayerBattleList(PlayerBattleList obj)
        {
            _playerBattleListPool.RecoverItem(obj);
        }

        public static SkillName GetSkillName()
        {
            return _skillNamePool.GetItem();
        }
        public static void RecoverSkillName(SkillName obj)
        {
            _skillNamePool.RecoverItem(obj);
        }

        public static SkillHit GetSkillHit()
        {
            return _skillHitPool.GetItem();
        }

        public static void RecoverSkillHit(SkillHit obj)
        {
            _skillHitPool.RecoverItem(obj);
        }

        public static AttackHit GetAttackHit()
        {
            return _attackHitPool.GetItem();
        }

        public static void RecoverAttackHit(AttackHit obj)
        {
            _attackHitPool.RecoverItem(obj);
        }

        public static Skill GetSkill()
        {
            return _skillPool.GetItem();
        }
        public static void RecoverSkill(Skill obj)
        {
            _skillPool.RecoverItem(obj);
        }
        public static RoundAttackEffect GetRoundAttackEffect()
        {
            return _roundAttackEffectPool.GetItem();
        }
        public static void RecoverRoundAttackEffect(RoundAttackEffect obj)
        {
            _roundAttackEffectPool.RecoverItem(obj);
        }

        public static MarchSquare GetMarchSquare()
        {
            return _marchSquarePool.GetItem();
        }
        public static void RecoverMarchSquare(MarchSquare obj)
        {
            _marchSquarePool.RecoverItem(obj);
        }

        public static RoundFightFlyText GetRoundFightFlyText()
        {
            return _roundFightFlyTextPool.GetItem();
        }
        public static void RecoverRoundFightFlyText(RoundFightFlyText obj)
        {
            _roundFightFlyTextPool.RecoverItem(obj);
        }
     
    }

    internal class RtsServerInfoPool : ClassObjectPool<RtsServerInfo>
    {
        public RtsServerInfoPool(int capacity) : base(capacity)
        {
        }

        public RtsServerInfoPool(int capacity, bool enableAutoShrink, int idleMaxCount, int frameShrinkCount, float shrinkIntervalTime) : base(capacity, enableAutoShrink, idleMaxCount, frameShrinkCount, shrinkIntervalTime)
        {
        }

        protected override void OnReset(RtsServerInfo obj)
        {
            obj.OnReset();
        }
    }
    internal class SkillHitElementListPool : ClassObjectPool<SkillHitElementList>
    {
        protected override void OnReset(SkillHitElementList obj)
        {
            obj.OnReset();
        }
        public SkillHitElementListPool(int capacity) : base(capacity)
        {

        }
    }
    internal class AttackHitTempPool : ClassObjectPool<AttackHitTemp>
    {
        protected override void OnReset(AttackHitTemp obj)
        {
            obj.OnReset();
        }

        public AttackHitTempPool(int capacity) : base(capacity)
        {

        }
    }
    internal class MarchLinePointPool : ClassObjectPool<MarchLinePoint>
    {
        protected override void OnReset(MarchLinePoint obj)
        {
            obj.OnReset();
        }

        public MarchLinePointPool(int capacity) : base(capacity)
        {

        }
    }
    internal class LineInfoPool : ClassObjectPool<LineInfo>
    {
        protected override void OnReset(LineInfo obj)
        {
            obj.OnReset();
        }

        public LineInfoPool(int capacity) : base(capacity)
        {

        }
    }
    internal class PlayerBattleListPool: ClassObjectPool<PlayerBattleList>
    {
        protected override void OnReset(PlayerBattleList obj)
        {
            obj.OnReset();
        }

        public PlayerBattleListPool(int capacity) : base(capacity)
        {

        }
    }
    internal class SkillNamePool : ClassObjectPool<SkillName>
    {
        protected override void OnReset(SkillName obj)
        {
            obj.OnReset();
        }

        public SkillNamePool(int capacity) : base(capacity)
        {

        }
    }
    internal class SkillHitPool : ClassObjectPool<SkillHit>
    {
        protected override void OnReset(SkillHit obj)
        {
            obj.OnReset();
        }

        public SkillHitPool(int capacity) : base(capacity)
        {

        }
    }
    internal class AttackHitPool : ClassObjectPool<AttackHit>
    {
        protected override void OnReset(AttackHit obj)
        {
            obj.OnReset();
        }

        public AttackHitPool(int capacity) : base(capacity)
        {
        }
    }
    internal class SkillPool : ClassObjectPool<Skill>
    {
        protected override void OnReset(Skill obj)
        {
            obj.OnReset();
        }

        public SkillPool(int capacity) : base(capacity)
        {
        }
    }

    internal class RoundAttackEffectPool : ClassObjectPool<RoundAttackEffect>
    {
        protected override void OnReset(RoundAttackEffect obj)
        {
            obj.OnReset();
        }

        public RoundAttackEffectPool(int capacity) : base(capacity)
        {
        }
    }

    internal class RoundFightFlyTextPool : ClassObjectPool<RoundFightFlyText>
    {
        public RoundFightFlyTextPool(int capacity) : base(capacity)
        {
        }

        protected override void OnReset(RoundFightFlyText obj)
        {
            obj.OnReset();
        }
    }
  
    

    internal class EffectControllerPool : ClassObjectPool<EffectController>
    {
        public EffectControllerPool(int capacity) : base(capacity)
        {
        }

        protected override void OnReset(EffectController obj)
        {
            obj.OnReset();
        }
    }

    

    internal class MarchSquarePool : ClassObjectPool<MarchSquare>
    {
        public MarchSquarePool(int capacity) : base(capacity)
        {
        }

        protected override void OnReset(MarchSquare obj)
        {
            obj.OnReset();
        }
    }

}